package com.grj.park.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.grj.park.common.R;
import com.grj.park.domain.Investors;
import com.grj.park.domain.User;
import com.grj.park.service.InvestorsService;
import com.grj.park.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("investors")
public class InvestorsController {

    private final InvestorsService investorsService;

    @GetMapping
    public R<List<Investors>> getInvestors(){
        return R.ok(investorsService.list());
    }

    @PostMapping
    public R<?> saveInvestors(@RequestBody Investors investors){
        LambdaQueryWrapper<Investors> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Investors::getInvestorName, investors.getInvestorName());
        Investors one = investorsService.getOne(queryWrapper);
        if (one != null){
            return R.fail("投资人名字已存在");
        }
        investorsService.save(investors);
        return R.okMsg("添加投资人成功");
    }
}
